<?php

// $p = $_GET['p'];
$userscount = GetUsersCount();
$pagecount = (int)($userscount/USERS_PER_PAGE) + ($userscount%USERS_PER_PAGE != 0);

if($p > $pagecount) $p = $pagecount;
if($p < 1) $p = 1;
$start = ($p - 1)*USERS_PER_PAGE;

$users = GetAllUsersByNanoPoints($start, USERS_PER_PAGE);

?>
<table id="rank_table" class="mc_table">
<tr>
	<th class="rt1">Rang</th>
	<th class="rt2">Pseudo</th>
	<th class="rt3">Victoires</th>
	<th class="rt4">Défaites</th>
	<th class="rt5">Ratio</th>
</tr>

<?php
	
$r = $p*USER_PER_PAGE + 1;
foreach($users as $u)
{
	echo '<tr><td class="rt1">' . ($r + ($p-1)*USERS_PER_PAGE) . '</td><td class="rt2"><a href="profil.php?id=' . $u->id . '">' . $u->name . '</a></td><td class="rt3">' . $u->nanowin . '</td><td class="rt4">' . $u->nanodefeat . '</td><td class="rt5">' . (($u->nanodefeat+$u->nanowin)?100*round($u->nanowin/($u->nanodefeat+$u->nanowin),2):0) . '%</td></tr>';
	$r++;
}

?>
</table>
<div id="rank_pages">
<?php
	if($p != 1) echo '<a href="nanorank.php?p=' . ($p - 1) . '">Précédente</a> ';
	echo 'Page ' . $p;
	if($p != $pagecount) echo ' <a href="nanorank.php?p=' . ($p + 1) . '">Suivante</a>';
?>